<%-- 
    Document   : create_post_db
    Created on : 31 May, 2012, 10:26:50 PM
    Author     : bharat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>

<!DOCTYPE html>
<%
    // String username = (String) session.getAttribute("username");
    // if(username!=null){
    Connection con = null;
    PreparedStatement pstmt2 = null;
    try {

        Class.forName("oracle.jdbc.driver.OracleDriver");
        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");

        con.setAutoCommit(false);
        String type = request.getParameter("type");
        String subject = request.getParameter("subject");
        String post = request.getParameter("post");
        String usr_name = request.getParameter("usr_name");

        pstmt2 = con.prepareStatement("insert into posts values(posts_seq.nextval,?,?,?,to_char(SYSDATE, 'DD-Mon-YYYY hh24:mi:ss'),0,0,?)");
        pstmt2.setString(1, type);
        pstmt2.setString(2, subject);
        pstmt2.setString(3, post);
        pstmt2.setString(4, usr_name);
        pstmt2.executeUpdate();
        con.commit();
        response.sendRedirect(".acc");
    } catch (Exception e) {
        con.rollback();
        out.println("Posting failed.");
        out.println(e.getMessage());
        e.printStackTrace();
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (Exception e) {
            }
        }
        if (pstmt2 != null) {
            try {
                pstmt2.close();
            } catch (Exception e) {
                response.sendError(502, e.getMessage());
            }
        }
    }
    // }
%>      


